<?php /* @var $this Controller */ ?>
<?php
Yii::app()->clientScript->scriptMap=array(
	'jquery.js'=>false,
	'jquery.yiiactiveform.js'=>false,
        //'styles.css'=>false,
	);
CHtml::$errorContainerTag = 'span';
	?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

		<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/templates/foundation.css">
		<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/templates/foundation-icons.css">
		<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/custom.css">

		<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/jquery.js"></script>
		<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/angular.js"></script>
		<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/modernizr.js"></script>
		<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/yii/jquery.yiiactiveform.js"></script>

		<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/js/app.js"></script>
		<script type="text/javascript">
		$.fn.yiiactiveform.defaults = $.extend({errorCssClass: 'error'},$.fn.yiiactiveform.defaults);
		</script>

		<meta class="foundation-mq-small" />
		<meta class="foundation-mq-medium" />
		<meta class="foundation-mq-large" />
		<meta class="foundation-mq-xlarge" />
		<meta class="foundation-mq-xxlarge" />
		<meta class="foundation-mq-topbar" />

		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
		<meta name="language" content="en" />

		<title><?php echo CHtml::encode($this->pageTitle); ?></title>
	</head>

	<body ng-app="ahaglaApp">

		<div class="">
			<div class="">
				<!-- Navigation -->
				<div class="top-bar" data-topbar="">
					<ul class="title-area">
						<!-- Title Area -->

						<li class="name">
							<h1><a href="#"><?php echo CHtml::encode(Yii::app()->name); ?></a></h1>
						</li>

						<li class="toggle-topbar menu-icon">
							<a href="#"><span>menu</span></a>
						</li>
					</ul>
					<?php
						$menu = array();
						$bMenu = array();
						$catalogs = Catalog::model()->findAll();

						function hasChild($catalogs, $catalog){
							$hasChild = false;
							for($j=0; $j<count($catalogs); $j++) {
								if($catalog->id == $catalogs[$j]->parent){
									$hasChild = true;
									break;
								}
							}
							return $hasChild;
						}

						function buildMenu($menuItem, $catalog, $catalogs){
							$items = array();
							for($i=0; $i<count($catalogs); $i++) {
								if($catalogs[$i]->parent == $catalog->id){
									$subMenuItem = array(
										'label'=>$catalogs[$i]->title, 'url'=>array('catalog/view/'.$catalogs[$i]->id),
									);
									
									if(hasChild($catalogs, $catalogs[$i])){
										$subMenuItem = buildMenu($subMenuItem, $catalogs[$i], $catalogs);
									}
									array_push($items, $subMenuItem);
								}
							}
							$menuItem['items'] = $items;
							$menuItem['itemOptions']=array('class'=>'has-dropdown not-click');
							return $menuItem;
						}

						for($i=0; $i<count($catalogs); $i++) {
							$menuItem = array('label'=>$catalogs[$i]->title, 'url'=>array('catalog/view/'.$catalogs[$i]->id));

							if(!$catalogs[$i]->parent){
								if(hasChild($catalogs, $catalogs[$i])){
									$menuItem = buildMenu($menuItem, $catalogs[$i], $catalogs);
								}
								array_push($menu, $menuItem);
							}
						}
						
					?>
					<div class="top-bar-section">
						<?php $this->widget('zii.widgets.CMenu',array(
							'activateParents'=>true,
							'submenuHtmlOptions' => array(
                    			'class' => 'dropdown',
                			),
							'items'=>array(
								array('label'=>'Home', 'url'=>array('/site/index')),
								array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
								array('label'=>'Contact', 'url'=>array('/site/contact')),
								array('label'=>'News', 'url'=>array('/news/index')),
								array('label'=>'Catalogs', 'url'=>'#',
									'itemOptions'=>array('class'=>'has-dropdown not-click'),
									'items'=>$menu
									),
								array('label'=>'Admin', 'visible'=>!Yii::app()->user->isGuest, 'url'=>'#',
									'itemOptions'=>array('class'=>'has-dropdown not-click'),
									'items'=>array(
										array('label'=>'Catalogs', 'url'=>array('/adminCatalog/admin'), 'visible'=>!Yii::app()->user->isGuest),
										array('label'=>'Products', 'url'=>array('/adminCatalogItem/admin'), 'visible'=>!Yii::app()->user->isGuest),
										array('label'=>'Users', 'url'=>array('/user/admin'), 'visible'=>!Yii::app()->user->isGuest),
										)
									),
								array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
								array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
								),
								)); ?>
								
								<div class="row">
									<form method="GET" action="<?php echo $this->createUrl('search/index') ?>">
										<div class="small-12 large-3 medium-3 columns right">
											<ul class="row collapse">
												<li class="small-12 medium-8 columns">
													<input placeholder="Search in catalogs..." name="q" type="search">
												</li>

												<li class="small-12 medium-4 columns">
													<button type="submit" class="small-12 columns button" href="#">Search</button>
												</li>
											</ul>
										</div>
									</form>
								</div>
							</div>
						</div><!-- End Navigation -->
					</div>
				</div>

				<div class="">
					<div class="">
						<?php if(isset($this->breadcrumbs)):?>
						<?php $this->widget('zii.widgets.CBreadcrumbs', array(
							'links'=>$this->breadcrumbs,
							'separator'=>''
							)); ?><!-- breadcrumbs -->
						<?php endif?>
					</div>
				</div>


				<div class="row">
					<?php echo $content; ?>
				</div>

				<footer class="row">
					<div class="large-12 columns">
						<hr>
						<div class="row">
							<div class="small-4 large-4 medium-4 columns left">
								<h2 class="text-uppercase text-height-normal"><a>OOO "AHAGLASS"</a></h2>
								<div class="text-secondary">
									<h4 class="text-height-normal">
										<small>ul isakovskogo, d 22, korp 1</small>
										<br/>
										<small>Russia, Moscow 123181</small>
										<br/>
										<small>contact@ahaglass.com</small>
										<br/>
										<small>495-210-27-13</small>
										<br/>
										<small>497-362-27-13</small>
										<br/>
									</h4>
								</div>
							</div>
							<div class="small-4 large-4 medium-4 columns right">
								<h2 class="text-center text-secondary text-uppercase text-height-normal">Follow Us</h2>
								<h1>
									<a class="fi-social-facebook text-center small-4 large-4 medium-4 columns"></a>
									<a class="fi-social-google-plus text-center small-4 large-4 medium-4 columns"></a>
									<a class="fi-social-twitter text-center small-4 large-4 medium-4 columns"></a>
								</h1>
							</div>



<div class="flash-success">
	<?php 
	if(Yii::app()->user->hasFlash('subscribe'))
	echo '<div id="flashModal" class="reveal-modal" data-reveal>
			<h2>Subscription.</h2>
			<p class="lead">'.Yii::app()->user->getFlash('subscribe-lead').'</p>
			<p>'.Yii::app()->user->getFlash('subscribe').'</p>
			<a class="close-reveal-modal">&#215;</a>
		</div>';
	?>
</div>

							<div class="row">
								<form method="POST" action="<?php echo $this->createUrl('subscribtion/subscribe') ?>">
									<div class="small-12 large-4 medium-4 columns right">

										<div class="row collapse">
											<div class="small-12 medium-8 columns">
												<input type="email" placeholder="Enter E-Mail to subscribe" name="email" />
												<?php
													if(isset($this->catalog)){
														echo '<input type="hidden" name="catalog_id" value="'.$this->catalog->id.'" />';
													}
												?>
											</div>
											<div class="small-12 medium-4 columns">
												<input type="submit" class="postfix small-4 columns button" value="Subscribe" />
											</div>
										</div>

									</div>
								</form>
							</div>
						</div>

						<div class="row">
							<div class="large-6 columns tap-to-close">
								
									Copyright &copy; <?php echo date('Y'); ?> by My Company.<br/>
									All Rights Reserved.<br/>
									<?php echo Yii::powered(); ?>
								
							</div>

							<div class="large-6 columns">
								<?php $this->widget('zii.widgets.CMenu',array(
									'items'=>array(
										array('label'=>'Home', 'url'=>array('/site/index')),
										array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
										array('label'=>'Contact', 'url'=>array('/site/contact')),
										array('label'=>'Contact', 'url'=>array('/user/admin'), 'visible'=>!Yii::app()->user->isGuest),
										array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
										array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
										),
									'htmlOptions'=>array('class'=>'inline-list right')
									)); ?>
								</div>
							</div>
						</div>
					</footer>

					<script src="<?php echo Yii::app()->request->baseUrl; ?>/assets/foundation.js"></script>
					<script>
					//$(document).ready(function(){
						
					$(document).foundation();

					var doc = document.documentElement;
					doc.setAttribute('data-useragent', navigator.userAgent);

					$('#flashModal').foundation('reveal', 'open');
				//});
					</script>
				</body>
				</html>
